package com.jingshui.Controller;

import com.alibaba.fastjson.JSONObject;
import com.jingshui.Entity.User;
import com.jingshui.Service.ReferrerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import orm.base.Ex.BaseControllerEx;

import java.util.Map;

/**
 * Created by ashin on 2017/10/9.
 */

@Controller
@Scope("prototype")
@RequestMapping("/referrer")
public class ReferrerController extends BaseControllerEx {


    @Autowired
    ReferrerService referrerService;

    @Override
    protected void init() {
        super.init(referrerService);
    }

    @Override
    protected JSONObject doInsert(@RequestParam Map<String, Object> map) throws Exception {
        User user = (User)session.getAttribute("user");
        map.put("refer",user.getId());
//        map.put("refer","16");
        return super.doInsert(map);
    }

    @Override
    protected JSONObject doQuery(@RequestParam Map map) throws Exception {
        User user = (User)session.getAttribute("user");
        map.put("refer",user.getId());
//        map.put("refer","16");
        return super.doQuery(map);
    }

    @RequestMapping(value = "/doQueryAdmin",method = RequestMethod.POST)
    protected JSONObject doQueryAdmin(@RequestParam Map map) throws Exception {
        return super.doQuery(map);
    }

    /**
     * 获得用户推荐相关信息
     * @param map
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/doGetReferrerCount",method = RequestMethod.POST)
    protected JSONObject doGetReferrerCount(@RequestParam Map map) throws Exception {
        User user = (User)session.getAttribute("user");
        map.put("refer",user.getId());
//        map.put("refer","16");
        return referrerService.getReferrerCount(map);
    }


}
